package com.tgpms.web.element.controller;

import com.tgpms.exception.ExceptionExplain;
import com.tgpms.exception.QueryException;
import com.tgpms.util.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.annotation.Resource;
import com.tgpms.auth.security.TokenService;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.tgpms.common.Result;
import com.tgpms.web.element.entity.WsQualityDispute;
import com.tgpms.web.element.service.IWsQualityDisputeService;

/**
 * <p>
 * 质量争议问题 控制层
 * </p>
 *
 * @author jl
 * @since 2020-07-08
 */
@Api(value = "WsQualityDisputeController", tags = "质量争议问题相关接口")
@RestController
@RequestMapping("/ev/WsQualityDispute")
public class WsQualityDisputeController {

	private final Logger log = LoggerFactory.getLogger(WsQualityDisputeController.class);
	
	@Resource
	private IWsQualityDisputeService service;
	@Resource
	private TokenService tokenService;

	/**
	 * 查询质量争议问题信息
	 **/
	@ApiOperation(value = "查询质量争议问题信息", notes = "查询质量争议问题信息", httpMethod = "GET")
	@RequestMapping(value = "/selWsQualityDisputeList")
	public Result selWsQualityDisputeList(@RequestParam Map<String, Object> params) {
		Result result = new Result();
		try {
			result = service.selWsQualityDisputeList(params);
		} catch (Exception e) {
			e.printStackTrace();
			result.setSuccess(false);
			result.setMsg(ExceptionExplain.ERROR_BY_QUERY.getExplain());
			throw new QueryException(ExceptionExplain.ERROR_BY_QUERY.getExplain());
		}
		return result;
	}
	
	@ApiOperation(value = "新增质量争议问题接口",notes = "新增质量争议问题接口",httpMethod = "POST")
	@PostMapping(value = "/addWsQualityDisputeInfo")
	public Result addWsQualityDisputeInfo(@RequestBody WsQualityDispute en,HttpServletRequest request) {
		log.info("新增质量争议问题接口接收到的参数为: "+en.toString());
		Result result = new Result();
		try{
			String insertName = tokenService.getUserName(request);
			en.setInsertUser(insertName);
			result = service.addWsQualityDispute(en,result);
		} catch (Exception e) {
			e.printStackTrace();
			result.setSuccess(false);
			result.setMsg("增加异常");
			return result;
		}
		return result;
	}
	
	@ApiOperation(value = "修改质量争议问题接口",notes = "修改质量争议问题接口",httpMethod = "PUT")
	@PutMapping(value = "/updateWsQualityDisputeInfo")
	public Result updateWsQualityDisputeInfo(@RequestBody WsQualityDispute en,HttpServletRequest request) {
		log.info("修改质量争议问题接口接收到的参数为: "+en.toString());
		Result result = new Result();
		try{
			String insertName = tokenService.getUserName(request);
			en.setModifyUser(insertName);
			en.setModifyDate(new Date());
			result = service.updateWsQualityDispute(en,result);
		} catch (Exception e) {
			e.printStackTrace();
			result.setSuccess(false);
			result.setMsg("修改异常");
			return result;
		}
		return result;
	}
	
	@ApiOperation(value = "删除质量争议问题接口",notes = "删除质量争议问题接口",httpMethod = "DELETE")
	@DeleteMapping(value = "/deleteWsQualityDisputeInfo")
	public Result deleteWsQualityDisputeInfo(@RequestParam Serializable id,HttpServletRequest request) {
		log.info("删除质量争议问题接口接收到的参数为: {id: "+id+" }");
		Result result = new Result();
		try{
			result = service.deleteWsQualityDispute(id,result);
		} catch (Exception e) {
			e.printStackTrace();
			result.setSuccess(false);
			result.setMsg("删除异常");
			return result;
		}
		return result;
	}
}
